package com.bangcommunity.bbframe.mq.kafka.interceptor;

import com.bangcommunity.bbframe.common.annotation.BeanOrder;
import com.bangcommunity.bbframe.mq.IQtMessager;
import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * Created by tanghc on 17/2/4.
 */
@BeanOrder(order = -1)
public class QtMonitorKafkaProducerInterceptor implements ProducerInterceptor<IQtMessager, IQtMessager> {
    @Override
    public ProducerRecord<IQtMessager, IQtMessager> onSend(ProducerRecord<IQtMessager, IQtMessager> record) {
        if (record == null) {
            return null;
        }
        IQtMessager value = record.value();
        if (value == null) {
            return record;
        }
        value.attach("monitor", new String("test kafka monitor"));

        return record;
    }

    @Override
    public void onAcknowledgement(RecordMetadata metadata, Exception exception) {

    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
